package mybatis.hr.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


public class DatabaseManager {
	//sqlsession객체를 생성해주는 객체로 어플리케이션에 하나만 생성해야 한다.
	private SqlSessionFactory factory;
	private static DatabaseManager instance = new DatabaseManager();
	
	private DatabaseManager(){
		//SqlSessionFactory는 sqlSessionFactoryBuilder를 통해 생성
		//-mybatis 설정 전달(InputStream)
		InputStream in = null;
		try {
			in = Resources.getResourceAsStream("mybatis/hr/dao/config/mybatis-config.xml");
		} catch (IOException e) {
			e.printStackTrace();
		}
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		factory=builder.build(in);
		
	}
	
	public static DatabaseManager getInstance(){
		return instance;
	}
	public SqlSessionFactory getSqlSessionFactory(){
		return factory;
	}
}
